package org.deadline.service.config;

import java.util.List;
import org.deadline.model.config.Country;
import org.deadline.repository.config.CountryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class CountryServiceImpl implements CountryService {

	@Autowired
    CountryRepository countryRepository;

	public long countAllCountrys() {
        return countryRepository.count();
    }

	public void deleteCountry(Country country) {
        countryRepository.delete(country);
    }

	public Country findCountry(Long id) {
        return countryRepository.findOne(id);
    }

	public List<Country> findAllCountrys() {
        return countryRepository.findAll();
    }

	public List<Country> findCountryEntries(int firstResult, int maxResults) {
        return countryRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveCountry(Country country) {
        countryRepository.save(country);
    }

	public Country updateCountry(Country country) {
        return countryRepository.save(country);
    }
}
